package com.yh.jucTest;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName Main
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/12/15 11:31
 */
public class Main {

    public static void main(String[] args) throws InterruptedException {
        AtomicInteger aiShare = new AtomicInteger();
        List<Integer> aiShare2 = new ArrayList<>();
        CountDownLatch countDownLatch = new CountDownLatch(10);
        aiShare2.add(0);
        ThreadPoolExecutor TEST_POOL = new ThreadPoolExecutor(10, 20, 10, TimeUnit.MINUTES, new LinkedBlockingQueue<>(5));
        for (int i = 0; i < 10; i++) {
            TEST_POOL.execute(new Accumlator2(aiShare, countDownLatch));
        }
//        List<Thread> list = new ArrayList<>();
        /*for (int i = 0; i < 10; i++) {
            Thread t = new Thread(new Accumlator(aiShare2));
            list.add(t);
            t.start();
        }*/
        /*for (int i = 0; i < 10; i++) {
            Thread t = new Thread(new Accumlator2(aiShare));
            list.add(t);
            t.start();
        }
        for (Thread t : list) {
            t.join();
        }*/
        /*for (;;) {
            if (TEST_POOL.getCompletedTaskCount() >= 10) {
                break;
            }
        }*/
        countDownLatch.await();
        TEST_POOL.shutdownNow();
        System.out.println(aiShare);
//        System.out.println(aiShare2);

    }
}
